<template>
	<view class="discover-container" @touchstart="handleTouchStart" @touchend="handleTouchEnd">
		<!-- 搜索栏 -->
		<view class="search-bar">
			<text class="icon-text">🔍</text>
			<input type="text" placeholder="搜索公告" />
			<button class="search-btn">搜索</button>
		</view>

		<!-- 公告列表 -->
		<view class="announcement-list">
			<view class="announcement-item" v-for="(item, index) in announcements" :key="index">
				<view class="announcement-content">
					<view class="announcement-text">
						<view class="announcement-title">{{ item.title }}</view>
						<view class="announcement-time">{{ item.time }}</view>
					</view>
				</view>
				<view class="announcement-right" v-if="item.hasImage">
					<view class="announcement-image">
						<image src="/static/announcement/missing-image.png" alt="公告图片" />
					</view>
				</view>
				<view class="announcement-right-placeholder" v-else></view>
			</view>
		</view>
		
		<!-- 底部 LOGO -->
		<view class="footer">
			<view class="logo">LianArt</view>
			<view class="platform-name">数字藏品平台</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'DiscoverPage',
	data() {
		return {
			announcements: [
				{
					title: '上杉越即将开启寄售',
					time: '2025-03-07 20:52',
					hasImage: true
				},
				{
					title: '奇迹造纸术即将开启寄售',
					time: '2025-03-07 20:52',
					hasImage: false
				},
				{
					title: '秀山晴雨最新限价调整',
					time: '2025-03-07 20:50',
					hasImage: true
				},
				{
					title: '游龙最新限价调整',
					time: '2025-03-07 20:49',
					hasImage: false
				},
				{
					title: '隼现已加入推荐区',
					time: '2025-03-07 20:49',
					hasImage: true
				}
			],
			startX: 0,
			endX: 0
		}
	},
	methods: {
		handleTouchStart(e) {
			this.startX = e.touches[0].clientX;
		},
		handleTouchEnd(e) {
			this.endX = e.changedTouches[0].clientX;
			const diffX = this.startX - this.endX;
			
			// 判断是否为水平滑动
			if (Math.abs(diffX) > 50) {
				// 发送滑动方向
				this.$emit('swipe', diffX > 0 ? 'left' : 'right');
			}
		}
	}
}
</script>

<style scoped>
.discover-container {
	background-color: #9BBFE0;
	min-height: 100vh;
	width: 100%;
	max-width: 100%;
	padding: 16px;
	padding-top: calc(16px + var(--status-bar-height, 20px)); /* 添加状态栏高度 */
	padding-bottom: 72px;
	font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
	color: #333;
	box-sizing: border-box;
}

/* 搜索栏样式 */
.search-bar {
	background: rgba(255, 255, 255, 0.9);
	border-radius: 16px;
	padding: 8px 16px;
	display: flex;
	align-items: center;
	margin-bottom: 12px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-bar input {
	flex: 1;
	border: none;
	background: none;
	margin: 0 12px;
	font-size: 14px;
	color: #333;
	outline: none;
	height: 28px;
}

.search-btn {
	background: #FFD700;
	border: none;
	padding: 4px 14px;
	border-radius: 20px;
	color: #333;
	font-size: 14px;
	cursor: pointer;
	height: 28px;
	line-height: 20px;
}

/* 公告列表样式 */
.announcement-list {
	background: rgba(255, 255, 255, 0.9);
	border-radius: 16px;
	overflow: hidden;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.announcement-item {
	padding: 16px;
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	border-bottom: 1px solid rgba(0, 0, 0, 0.05);
	position: relative; /* 为绝对定位的时间提供参考 */
}

.announcement-item:last-child {
	border-bottom: none;
}

.announcement-right {
	display: flex;
	align-items: flex-start;
}

.announcement-image {
	width: 80px;
	height: 80px;
	border-radius: 8px;
	overflow: hidden;
	background-color: #f0f0f0;
}

.announcement-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.announcement-right-placeholder {
	width: 80px; /* 与图片宽度一致 */
}

.announcement-content {
	flex: 1;
	margin-right: 16px;
	min-height: 80px; /* 与图片高度一致 */
	display: flex;
	align-items: flex-start;
}

.announcement-text {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	min-height: 80px;
	width: 100%;
}

.announcement-title {
	font-size: 15px;
	font-weight: 500;
	line-height: 1.4;
	padding: 0;
	margin: 0;
}

.announcement-time {
	font-size: 12px;
	color: #888;
	padding: 0;
	margin: 0;
	position: absolute;
	bottom: 16px; /* 与 announcement-item 的 padding 对应 */
}

/* 动画效果 */
@keyframes fadeIn {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: translateY(0); }
}

.announcement-item {
	animation: fadeIn 0.5s ease forwards;
}

.announcement-item:nth-child(1) { animation-delay: 0.1s; }
.announcement-item:nth-child(2) { animation-delay: 0.2s; }
.announcement-item:nth-child(3) { animation-delay: 0.3s; }
.announcement-item:nth-child(4) { animation-delay: 0.4s; }
.announcement-item:nth-child(5) { animation-delay: 0.5s; }

/* 底部 LOGO */
.footer {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 16px 0;
	opacity: 0.7;
	width: 100%;
	margin-top: 20px;
}

.logo {
	font-size: 16px;
	font-weight: 600;
	margin-bottom: 4px;
}

.platform-name {
	font-size: 13px;
}
</style> 